<template>
<!-- 分销-代理商列表-->
  <div>
    <Card :bordered="false" dis-hover class="ivu-mt" :padding= "0">
      <div class="new_card_pd">
      <Form
        ref="formValidate"
        :model="formValidate"
        :label-width="labelWidth"
        :label-position="labelPosition"
        @submit.native.prevent
        inline
      >
        <FormItem label="搜索：" label-for="status">
            <Input
              v-model="formValidate.keyword"
              placeholder="请输入uid或者名称"
              class="input-add mr14"
            />
            <Button type="primary" @click="search">查询</Button>
        </FormItem>
      </Form>
      </div>
    </Card>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <Button type="primary" @click="groupAdd()" class="ml20 ">添加代理商</Button>
      <Table
        :columns="columns1"
        :data="tabList"
        ref="table"
        class="mt25"
        :loading="loading"
        highlight-row
        no-userFrom-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
      >
        <template slot-scope="{ row, index }" slot="avatar">
          <viewer>
            <div class="tabBox-img">
              <img v-lazy="row.avatar" />
            </div>
          </viewer>
        </template>
        <template slot-scope="{ row, index }" slot="status">
          <i-switch
            v-model="row.division_status"
            :value="row.division_status"
            :true-value="1"
            :false-value="0"
            @on-change="onchangeIsShow(row)"
            size="large"
          >
            <span slot="open">显示</span>
            <span slot="close">隐藏</span>
          </i-switch>
        </template>
        <template slot-scope="{ row, index }" slot="action">
          <a @click="addTask(row)">查看员工</a>
          <Divider type="vertical" />
          <a @click="edit(row, '编辑')">编辑</a>
          <!-- <Divider type="vertical" /> -->
          <!-- <a @click="del(row, '删除这条信息', index)">删除</a> -->
        </template>
      </Table>
      <div class="acea-row row-right page">
        <Page
          :total="total"
          :current="formValidate.page"
          show-elevator
          show-total
          @on-change="pageChange"
          :page-size="formValidate.limit"
        />
      </div>
    </Card>
    <div class="task-modal">
      <Modal v-model="modal2" title="添加任务" footer-hide width="1000">
        <!-- <div class="header">
          <h4>搜索条件</h4>
          <div class="search">
            <div>
              <span>是否显示：</span>
              <Select v-model="taskData.status" style="width: 200px">
                <Option value="">全部</Option>
                <Option :value="1">显示</Option>
                <Option :value="0">不显示</Option>
              </Select>
            </div>
            <div>
              <span>任务名称：</span>
              <Input
                v-model="taskData.keyword"
                placeholder="请输入任务名称"
                style="width: 200px"
              />
            </div>
            <Button type="primary" @click="searchTask">搜索</Button>
          </div>
        </div> -->
        <div>
       <!--   <div class="add-task">
            <Button type="primary" @click="taskAdd()">添加等级任务</Button>
          </div> -->
          <div>
            <Table
              :columns="columns2"
              :data="taskTabList"
              ref="table"
              class="mt25"
              :loading="taskLoading"
              highlight-row
              no-userFrom-text="暂无数据"
              no-filtered-userFrom-text="暂无筛选结果"
            >
             <template slot-scope="{ row, index }" slot="avatar">
               <viewer>
                 <div class="tabBox-img">
                   <img v-lazy="row.avatar" />
                 </div>
               </viewer>
             </template>
            </Table>
            <div class="acea-row row-right page">
              <Page
                :total="taskTotal"
                :current="taskData.page"
                show-elevator
                show-total
                @on-change="pageTaskChange"
                :page-size="taskData.limit"
              />
            </div>
          </div>
        </div>
      </Modal>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
// import createLevel from "./components/createLevel";
import {
  membershipDataAddApi,
  membershipDataListApi,
  membershipDataEditApi,
  membershipSetApi,
  levelTaskSetApi,
  levelTaskListDataAddApi,
  levelTaskDataEditApi,
  levelTaskDataAddApi,
} from "@/api/membershipLevel";
import {
	divisionDown_list,
	divisionList
} from "@/api/setting";
export default {
  name: "list",
  // components: { createLevel },
  data() {
    return {
      grid: {
        xl: 7,
        lg: 7,
        md: 12,
        sm: 24,
        xs: 24,
      },
      modal1: false,
      modal2: false,
      formValidate: {
        page: 1,
        limit: 20,
        keyword:'',
		division_type:2
      },
      taskData: {
       page: 1,
       limit: 20,
       uid:'',
       division_type:3
      },
      total: 0,
      taskTotal: 0,
      tabList: [],
      taskTabList: [],
      columns1: [
        {
          key: "uid",
          width: 80,
          title: "用户UID",
        },
        {
          slot: "avatar",
          minWidth: 100,
          title: "头像",
        },
        {
          key: "nickname",
          minWidth: 100,
          title: "姓名",
        },
        // {
        //   key: "division_invite",
        //   minWidth: 80,
        //   title: "邀请码",
        // },
        {
          key: "division_percent",
          minWidth: 120,
          title: "分销比例(%)",
        },
        {
          key: "agent_count",
          minWidth: 130,
          title: "代理商数量",
        },
        {
          key: "two_brokerage",
          minWidth: 120,
          title: "订单数量",
        },
        {
          key: "division_end_time",
          minWidth: 130,
          title: "截至时间",
        },
        {
          slot: "status",
          minWidth: 80,
          title: "状态",
        },
        {
          fixed: "right",
          minWidth: 160,
          slot: "action",
          title: "操作",
        },
      ],
      columns2: [
        {
          key: "uid",
          minWidth: 35,
          title: "用户UID",
        },
		{
		  slot: "avatar",
		  minWidth: 100,
		  title: "头像",
		},
		{
			key: "nickname",
			   minWidth: 35,
			title: "姓名",
		},
		{
		  key: "division_percent",
		    minWidth: 35,
		  title: "分销比例(%)",
		},
		// {
		//   key: "division_end_time",
		//    minWidth: 35,
		//   title: "截至时间",
		// },
		// {
		//   key: "agent_count",
		//    minWidth: 35,
		//   title: "员工数量",
		// },
        // {
        //   // fixed: "right",
        //   minWidth: 120,
        //   slot: "action",
        //   title: "操作",
        // },
      ],
      FromData: null,
      loading: false,
      taskLoading: false,
      titleType: "group",
      groupAll: [],
      theme3: "light",
      labelSort: [],
      sortName: null,
      current: 0,
      model1: "",
      value1: "",
    };
  },
  computed: {
    ...mapState("admin/layout", ["isMobile"]),
    labelWidth() {
      return this.isMobile ? undefined : 96;
    },
    labelPosition() {
      return this.isMobile ? "top" : "right";
    },
  },
  watch: {
    $route(to, from) {
      if (this.$route.params.id) {
      } else {
      }
    },
  },
  mounted() {
    this.getList();
  },
  methods: {
    // bindMenuItem(name, index) {
    //   this.current = index;
    //   this.formValidate.gid = name.id;
    //   this.getListHeader();
    //   this.getList();
    // },
    // 列表1
    getList() {
      this.loading = true;
      divisionList(this.formValidate)
        .then(async (res) => {
          let data = res.data;
          this.tabList = data.list;
          this.total = data.count;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$Message.error(res.msg);
        });
    },
    // 列表2
    getTaskList() {
      this.taskLoading = true;
      divisionDown_list(this.taskData)
        .then(async (res) => {
          let data = res.data;
          this.taskTabList = data.list;
          this.taskTotal = data.count;
          this.taskLoading = false;
        })
        .catch((res) => {
          this.taskLoading = false;
          this.$Message.error(res.msg);
        });
    },
    pageChange(index) {
      this.formValidate.page = index;
      this.getList();
    },
    pageTaskChange(index) {
      this.taskData.page = index;
      this.getList();
    },
    // 表格搜索
    search() {
      this.formValidate.page = 1;
      this.getList();
    },
    searchTask() {
      this.taskData.page = 1;
      this.getTaskList();
    },
    // 添加表单
    groupAdd() {
      this.$modalForm(
        membershipDataAddApi({}, `/agent/division/agent/create/0`)
      ).then(() => this.getList());
    },
    taskAdd() {
      this.$modalForm(
        levelTaskDataAddApi(
          {},
          "/agent/level_task/create?level_id=" + this.taskData.id
        )
      ).then(() => this.getTaskList());
    },
    // 修改是否显示
    onchangeIsShow(row) {
      membershipSetApi(`agent/level/set_status/${row.id}/${row.status}`)
        .then(async (res) => {
          this.$Message.success(res.msg);
          this.getList();
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
    // 修改是否显示
    onchangeTaskIsShow(row) {
      levelTaskSetApi(`agent/level_task/set_status/${row.id}/${row.status}`)
        .then(async (res) => {
          this.$Message.success(res.msg);
          this.getList();
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
    //添加等级任务
    addTask(row) {
      // this.id = row.id;
      this.modal2 = true;
      this.taskData.uid = row.uid;
      this.getTaskList();
    },
    // 编辑
    edit(row) {
      this.$modalForm(
        membershipDataEditApi({}, `agent/division/agent/create/${row.uid}`)
      ).then(() => this.getList());
    },
    // 删除
    // del(row, tit, num) {
    //   let delfromData = {
    //     title: tit,
    //     num: num,
    //     url: `agent/division/del/1/${row.uid}`,
    //     method: "DELETE",
    //     ids: "",
    //   };
    //   this.$modalSure(delfromData)
    //     .then((res) => {
    //       this.$Message.success(res.msg);
    //       this.tabList.splice(num, 1);
    //       if (!this.tabList.length) {
    //         this.formValidate.page =
    //             this.formValidate.page == 1 ? 1 : this.formValidate.page - 1;
    //       }
    //       this.getList();
    //     })
    //     .catch((res) => {
    //       this.$Message.error(res.msg);
    //     });
    // },
  },
};
</script>

<style scoped lang="stylus">
/deep/ .ivu-menu-vertical .ivu-menu-item-group-title {
  display: none;
}

/deep/ .ivu-menu-vertical.ivu-menu-light:after {
  display: none;
}

.left-wrapper {
  height: 904px;
  background: #fff;
  border-right: 1px solid #dcdee2;
}

.menu-item {
  // z-index 50
  position: relative;
  display: flex;
  justify-content: space-between;
  word-break: break-all;

  .icon-box {
    z-index: 3;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
  }

  &:hover .icon-box {
    display: block;
  }

  .right-menu {
    z-index: 10;
    position: absolute;
    right: -106px;
    top: -11px;
    width: auto;
    min-width: 121px;
  }
}

.tabBox-img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}

.ivu-menu {
  z-index: auto;
}

.header, .headers {
  display: flex;
  flex-direction: column;
  background-color: #f2f2f2;
  padding: 8px;

  .search {
    display: flex;
    align-items: center;

    >div {
      margin-right: 10px;
    }
  }
}

.headers {
  background-color: #fff;
}

/deep/ .ivu-modal-mask {
  z-index: 100 !important;
}

/deep/ .ivu-modal-wrap {
  z-index: 100 !important;
}

.add-task {
  margin: 10px 0;
}
</style>
